/**
 * ContestPoints管理初始化
 */
var ContestPoints = {
    id: "ContestPointsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1,
    width: '850px',
    height: '580px'
};

/**
 * 初始化表格的列
 */
ContestPoints.initColumn = function () {
    return [
        {field: 'selectItem', radio: false},
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '年度', field: 'year', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工姓名', field: 'empName', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '员工编号', field: 'empCode', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '公司级别', field: 'companyType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '公司级别编码', field: 'companyTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '竞赛类型', field: 'contestType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '竞赛类型编码', field: 'contestTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '获奖类型', field: 'winType', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '获奖类型编码', field: 'winTypeCode', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '积分', field: 'integral', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle',sortable: true},
            {title: '数据来源', field: 'dataOrigin', visible: false, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
ContestPoints.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ContestPoints.seItem = selected[0];
        return true;
    }
};

ContestPoints.checks = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        ContestPoints.seItem = selected;
        return true;
    }
};
/**
 * 点击添加ContestPoints
 */
ContestPoints.openAddContestPoints = function () {
    var index = layer.open({
        type: 2,
        title: '添加竞赛调考积分',
        area: [ContestPoints.width, ContestPoints.height], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/contestPoints/contestPoints_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看ContestPoints详情
 */
ContestPoints.openContestPointsDetail = function () {
    if (this.check()) {
        var selected = $('#' + this.id).bootstrapTable('getSelections');
        if(selected.length > 1){
            Feng.info("修改只能选择一条数据！");
            return false;
        }

        var index = layer.open({
            type: 2,
            title: '竞赛调考积分详情',
            area: [ContestPoints.width, ContestPoints.height], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/contestPoints/contestPoints_update/' + ContestPoints.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除ContestPoints
 */
ContestPoints.delete = function () {
    if (this.checks()) {
        var operation = function() {
            var ajax = new $ax(Feng.ctxPath + "/contestPoints/delete", function (data) {
                Feng.success("删除成功!");
                ContestPoints.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            var ids = "";
            for (var i in ContestPoints.seItem) {
                if (!ids) {
                    ids += ContestPoints.seItem[i].id;
                } else {
                    ids += "," + ContestPoints.seItem[i].id;
                }
            }
            ajax.set("contestPointsId", ids);
            ajax.start();
        };
        Feng.confirm("是否删除选中的"+ContestPoints.seItem.length +"数据？", operation);
    }
};
//
// ContestPoints.delete = function () {
//     if (this.checks()) {
//         var operation = function() {
//             var ajax = new $ax(Feng.ctxPath + "/integral/cleanData", function (data) {
//                 Feng.success("清理成功!");
//                 ContestPoints.table.refresh();
//             }
//             ajax.set("table", "contest_points");
//             ajax.start();
//         };
//         Feng.confirm("是否清空所有数据，数据清空后不可恢复", operation);
//     }
// };

/**
 * 查询ContestPoints列表
 */
ContestPoints.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    ContestPoints.table.refresh({query: queryData});
};

/**
 * 打开导入ContestPoints数据页面
 */
ContestPoints.import = function () {
    var index = layer.open({
        type: 2,
        title: '导入竞赛调考积分',
        area: ['600px', '500px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/contestPoints/contestPoints_import'
    });
    this.layerIndex = index;
    layer.full(index);
};

/**
 * 高级搜索
 */
ContestPoints.g_search = function () {
    var index = layer.open({
        type: 2,
        skin: 'layui-layer-molv',
        title: '高级搜索',
        area: ['900px', '500px'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/employee/g_search',
        btn: ['确定','关闭'],
        yes: function(index, layero){
            var queryData = window["layui-layer-iframe" + index].Employee.search2();

            ContestPoints.table.setQueryParams(queryData);
            ContestPoints.table.refresh();
            ContestPoints.table.empty();
            layer.close(index); //如果设定了yes回调，需进行手工关闭
        }
    });
    this.layerIndex = index;
};

ContestPoints.export = function(){
    window.open(Feng.ctxPath + '/contestPoints/export',"_parent");
    Feng.success("导出成功!");
};

$(function () {
    var defaultColunms = ContestPoints.initColumn();
    var table = new BSTable(ContestPoints.id, "/contestPoints/list", defaultColunms);
    table.setPaginationType("client");
    ContestPoints.table = table.init();
});
